//
//  AppConfig.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/5/24.
//
//  适配器

import Foundation

class Adapter {
    
    class Base {
        // 初始化App
        class func initAppInterface(window: UIWindow) {
            let tabbarController = SFTabbarController.init()
            window.backgroundColor = UIColor.white
            window.rootViewController = tabbarController
            window.makeKeyAndVisible()
        }
    }
    
}

// MARK:  环境参数配置
extension Adapter {
    
    struct Param {
        
        enum Kind {
            case scheme             // scheme
            case api_host           // api 域名
            case h5_host            // H5 域名
            case channel            // 渠道(网咯请求)
            case Rongyun_Appkey     // 融云 AppKey
            case GT_ID              // 个推ID
            case GT_AppKey          // 个推 AppKey
            case GT_Secret          // 个推 AppSecret
            case App_channel        // 渠道(安装统计)
        }
        
        static func get(kind: Kind) -> String {
            
            var InfoDict: [String:String]?
            
            #if DEBUG
            InfoDict = [
                "scheme"          : "http://",
                "api_host"        : "api.test.cbct.cn",
                "h5_host"         : "h5.test.cbct.cn",
                "Rongyun_Appkey"  : "25wehl3u2gjtw",
                "channel"         : "CBCT_TEST",
                "GT_ID"           : "ZOYhQaCGxnAZC76P9PLlh",
                "GT_AppKey"       : "0drBmSxTJ067JkxKOY3Fg",
                "GT_Secret"       : "B2LUYLnddh89Z742eVmSE5",
                "App_channel"     : "CBCT_TEST",
            ]
            #else
            InfoDict = [
                "scheme"          : "http://",
                "api_host"        : "api.cbct.cn",
                "h5_host"         : "www.seefm.cn",
                "Rongyun_Appkey"  : "tdrvipkstyd95",
                "channel"         : "AppStore",
                "GT_ID"           : "RsvYqBwTUh83d1OyH2fDt3",
                "GT_AppKey"       : "lrzOkmCq6F8ASypg7eXvn1",
                "GT_Secret"       : "jftGVaflCs5rssQvmmEQ52",
                "App_channel"     : "App Store",
            ]
            
            #endif
            
            var res: String?
            switch kind {
                case .scheme: res           = InfoDict?["scheme"]
                case .api_host: res         = InfoDict?["api_host"]
                case .h5_host: res          = InfoDict?["h5_host"]
                case .Rongyun_Appkey: res   = InfoDict?["Rongyun_Appkey"]
                case .channel: res          = InfoDict?["channel"]
                case .GT_ID: res            = InfoDict?["GT_ID"]
                case .GT_AppKey: res        = InfoDict?["GT_AppKey"]
                case .GT_Secret: res        = InfoDict?["GT_Secret"]
                case .App_channel: res      = InfoDict?["App_channel"]
            }
            return res ?? ""
        }
    }
    
}


// MARK:  UI 适配
extension Adapter {
    
    struct Screen {
        
        static func isFull() -> Bool {
            if #available(iOS 11.0, *) {
                if let insets = UIApplication.shared.keyWindow?.safeAreaInsets {
                    let orientation = UIApplication.shared.statusBarOrientation
                    switch orientation {
                    case .portrait, .portraitUpsideDown:
                        if insets.top == 44 || insets.bottom == 34 {
                            return false
                        }
                    case .landscapeLeft, .landscapeRight:
                        if insets.left == 44 || insets.right == 44 || insets.bottom == 21 {
                            return false
                        }
                    default:
                        break
                    }
                }
            }
            return true
        }
        
        // navigationBar
        static let statusBarHeight: CGFloat = isFull() ? 20:44
        static let navBarHeight: CGFloat = 44
        static let topHeight = statusBarHeight + navBarHeight
        
        // Tabbar
        static let tabbarHeight: CGFloat = isFull() ? tabbarContent:34+tabbarContent
        static let tabbarContent: CGFloat = 49
        static let tabbarHeightWithStandout: CGFloat = isFull() ? 49+20:34+49+20
        static let bottomMargin: CGFloat = isFull() ? 0:34
        
        // UIScreen
        static var width: CGFloat {
            return UIScreen.main.bounds.width
        }
        static var height: CGFloat {
            return UIScreen.main.bounds.height
        }
    }
    
}




